package com.huawei.hms.aaid.c;

import android.text.TextUtils;
import com.huawei.hms.aaid.constant.AaidIdConstant;
import com.huawei.hms.support.log.HMSLog;
import com.huawei.hms.utils.HEX;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public final class d {
    public static String a(String str, String str2) {
        String str3 = null;
        try {
            byte[] bytes = str.getBytes("UTF-8");
            if (TextUtils.isEmpty(str2)) {
                str2 = AaidIdConstant.SIGNATURE_SHA256;
            }
            MessageDigest instance = MessageDigest.getInstance(str2);
            instance.update(bytes);
            str3 = HEX.encodeHexString(instance.digest(), false);
        } catch (NoSuchAlgorithmException e) {
            HMSLog.e("SHACoder", "encrypt failed .");
        } catch (UnsupportedEncodingException e2) {
            HMSLog.e("SHACoder", "trans failed .");
        }
        return str3;
    }
}
